<template>
  <div>
    <van-nav-bar
        left-arrow
        @click-left="onClickLeft"
        title="修改设备信息"
    />
    <van-form @submit="onSubmit">
      <van-field
          v-model="form.id"
          name="设备编号"
          label="设备名称"
          placeholder="设备编号"
          disabled
          :rules="[{ required: true, message: '请填写设备编号' }]"
      />
      <van-field
          v-model="form.name"
          name="设备名称"
          label="设备名称"
          placeholder="设备名称"
          :rules="[{ required: true, message: '请填写设备名称' }]"
      />
      <van-field
          v-model="form.address"
          name="设备地址"
          label="设备地址"
          placeholder="设备地址"
          :rules="[{ required: true, message: '请填写设备地址' }]"
      />
      <van-field
          v-model="form.phone"
          name="扫码展示电话"
          label="扫码展示电话"
          placeholder="扫码展示电话"
          :rules="[{ required: true, message: '请填写扫码展示电话' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {machineGet, machineEdit} from "@/api/operator";
import {getLocalOpenId} from "@/utils/wxUtil";

export default {
  data() {
    return {
      form: {
        operatorId: getLocalOpenId(),
        id: this.$route.query.id,
        name: '',
        address: '',
        phone: ''
      }
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    onSubmit: function () {
      machineEdit(this.form).then(res => {
        this.$toast.success("修改成功！")
        this.$router.go(-1)
      })
    }
  },
  mounted() {
    machineGet(this.form).then(res=>{
      this.form.name=res.data.name
      this.form.address=res.data.address
      this.form.phone=res.data.phone
    })
  }
}
</script>

<style scoped>
</style>
